/**
 * Created by xgl on 2017/8/7.
 */
import webService from '../../../../api/config/channel/multi-channel'
import * as globalTypes from '../../../../mutation-types'

/* 技能组 start */
  /**
   * 查询技能组列表
   * @param data
   * @param data.page
   * @param data.limit
   * @param data.DisplayName  可选/在根据名称查询时/支持模糊查询
   * @returns {*}
   */
export const queryEmailQueue = ({commit, state, rootState, dispatch}, data) => {
  return webService.queryEmailQueue(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
   /**
   * 获取接入网站列表
   * @param data
   * @param data.platform 平台 "web" / app / sdk
   * @returns {*}
   */
export const queryWebchat = ({commit, state, rootState, dispatch}, data) => {
  return webService.queryWebchat(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
  /**
   * 根据id查询接入网站
   * @param data._id 接入网站id
   * @returns {*}
   */
export const queryWebchatCfgById = ({commit, state, rootState, dispatch}, data) => {
  return webService.queryWebchatCfgById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
   * 添加一个新的网站接入
   * @param data
   * @returns {*}
   */
export const webAddWebchatCfg = ({commit, state, rootState, dispatch}, data) => {
  return webService.addWebchatCfg(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
  /**
   * 修改网站接入
   * @param data
   * @returns {*}
   */
export const webUpdateWebchatCfg = ({commit, state, rootState, dispatch}, data) => {
  return webService.updateWebchatCfg(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
  /**
   * 检测在线咨询是否植入成功
   * @param data
   * location 要检查的网站
   * accessId
   * @returns {*}
   */
export const checkWebSiteEmebedScript = ({commit, state, rootState, dispatch}, data) => {
  return webService.checkWebSiteEmebedScript(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
  /**
   * 删除一个网站接入
   * @param data._id
   * @returns {*}
   */
export const deleteWebchatCfg = ({commit, state, rootState, dispatch}, data) => {
  return webService.deleteWebchatCfg(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
   /**
   * 查询全局配置
   * @param data {}
   * @returns {*}
   */
export const getVisitorData = ({commit, state, rootState, dispatch}, data) => {
  return webService.getGlobalSetById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
  /**
    * 保存访客端配置
    * @param data {}
    * @returns {*}
  */
export const saveVisitorSet = ({commit, state, rootState, dispatch}, data) => {
  return webService.saveGlobalSet(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
    * 获取在线咨询日程管理列表
    * @param data {}
    * @returns {*}
  */
export const getScheduleList = ({commit, state, rootState, dispatch}, data) => {
  return webService.webchatGetScheduleList(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
    * 添加在线咨询日程管理
    * @param data {}
    * @returns {*}
  */
export const addSchedule = ({commit, state, rootState, dispatch}, data) => {
  return webService.webchatAddSchedule(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
    * 修改在线咨询日程管理
    * @param data {}
    * @returns {*}
  */
export const webchatUpdateSchedule = ({commit, state, rootState, dispatch}, data) => {
  return webService.webchatUpdateSchedule(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
    * 删除在线咨询日程管理
    * @param data {}
    * @returns {*}
  */
export const webchatDelSchedule = ({commit, state, rootState, dispatch}, data) => {
  return webService.webchatDelSchedule(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
